<?php

$directory = v('directory');
$extensionId = v('extensionId');
$fileToTranslate = v('fileToTranslate');

?>

<!-- BreadCrump -->

<ul class="breadcrumb">
	<li>
		<a href="<?php p(url('[Loop]/page/admin/documentation/')); ?>" >Documentation</a>
		<span class="divider">/</span>
	</li>
	<li>
		<a href="<?php p(url('[Loop]/page/admin/documentation/extension/') . '?extensionId=' . $extensionId); ?>" ><?php p($extensionId); ?></a> 
		<span class="divider">/</span>
	</li>
	<li class="active">
		<?php p($directory); ?>
	</li>
</ul>

<!-- File description -->

<div>
	<h4 style="text-align: center;">
		<a href="<?php p(url('[Loop]/page/admin/documentation/extension/') . '?extensionId=' . $extensionId); ?>" >
			<?php echo $result['namespace']; ?>
		</a>\<?php p($result['classNameWithoutNamespace']);?>
	</h4>

	<?php

	// Is there a parent ?

	if (empty($result['parentClassName']) === false)
	{
		// Construct the parent extensionId

		$parentExtensionId = str_replace('\\', '-', $result['parentNameSpace']);


		// Get the path to the parent extension

		$pathToParentExtension = app()->getPathHelper()->convertExtensionIdToPath($parentExtensionId);


		// Try to get a path to the file

		$path = app()->getPathHelper()->getPathToClass($result['parentClassNameWithoutNamespace'], $parentExtensionId);


		// Is there a path ?

		if(empty($path) === true)
		{
			// No, it's a model

			$directoryParent = 'Model';
		}
		else
		{
			// Yes, it's a class

			$directoryParent = 'Class';
		}
	?>

		<p> 
			<b>Parent : </b>
			<a href="<?php p(url('[Loop]/page/admin/documentation/extension/') . '?extensionId=' . $parentExtensionId);?>">
				<?php echo $result['parentNameSpace']; ?>
			</a>\<a href="<?php p(url('[Loop]/page/admin/documentation/concept/') . '?extensionId=' . $parentExtensionId .'&directory=' . $directoryParent . '&file=' . $result['parentClassNameWithoutNamespace']);?>"><?php p($result['parentClassNameWithoutNamespace']); ?>
			</a>
		</p>		

	<?php
	}
	if (empty($result['description']['infos']) === false)
	{
	?>
		<!-- Description of the file-->

		<p> 
			<b>Description :</b>
			<?php p($result['description']['infos']); ?>
		</p>
	<?php
	}
	?>
	<!-- Namespace-->

	<p>
		<b>Namespace : </b>
		<a href="<?php p(url('[Loop]/page/admin/documentation/extension/') . '?extensionId=' . $extensionId); ?>" >
			<?php echo $result['namespace']; ?>
		</a>
	</p>


	<?php
		
		render
		(
			'[Loop]/Html/Snippet.RichDocumentation.html',
			array 
			(
				'extensionId' => $extensionId,
				'concept' => $directory,
				'file' => $fileToTranslate,
				'method' => null
			)
		);

	?>	
</div>


<div class="tabbable">
	<ul class="nav nav-tabs" id="myTab">
		<?php

		if (count($result['constants']) > 0)
		{
		?>		
			<li class="active">
				<a href="#constant" data-toggle="tab">Constant</a>
			</li>
		<?php
		}
		?>

		<?php

		if ($result['hasProperties'] == 1)
		{
		?>	
			<li <?php if (count($result['constants']) == 0)	{	?>	class="active" <?php } ?>>
				<a href="#attributes" data-toggle="tab">Attributes</a>
			</li>
		<?php
		}
		?>

		<?php

		if (count($result['objectProperties']) > 0)
		{
		?>
			<li <?php if (count($result['constants']) == 0 && $result['hasProperties'] == 0){	?>	class="active" <?php } ?>>	
				<a href="#properties" data-toggle="tab">Properties</a>
			</li>
		<?php
		}
		?>

		<?php

		if (count($result['ioProperties']) > 0 && $directory == 'Model')
		{
		?>
			<li>	
				<a href="#io" data-toggle="tab">I/O</a>
			</li>
		<?php
		}
		?>

		<?php

		if ($result['hasMethods'] == 1)
		{
		?>	
			<li <?php if (count($result['constants']) == 0 && $result['hasProperties'] == 0 && count($result['objectProperties']) == 0){	?>	class="active" <?php } ?>>			
				<a href="#methods" data-toggle="tab">Methods</a>
			</li>
		<?php
		}
		?>

		<?php

		if (isset($result['API']) === true)
		{
		?>	
			<li <?php if (count($result['constants']) == 0 && $result['hasProperties'] == 0 && count($result['objectProperties']) == 0  && $result['hasMethods'] == 0){	?>	class="active" <?php } ?>>			
				<a href="#APIs" data-toggle="tab">APIs</a>
			</li>
		<?php
		}
		?>	

		<?php
		if 
		(
			isset($result['dependencies']) === true && 
			count($result['dependencies']) >0
		)
		{
		?>
			<li <?php if (count($result['constants']) == 0 && $result['hasProperties'] == 0 && count($result['objectProperties']) == 0  && $result['hasMethods'] == 0 && isset($result['API']) === false){	?>	class="active" <?php } ?>>			
				<a href="#dependencies" data-toggle="tab">Dependencies</a>
			</li>
		<?php
		}
		?>	


	</ul>
</div>


<div class="tab-content">

	
	<div class="tab-pane active" id="constants">
		<!-- Constants-->
		<?php

		if (count($result['constants']) > 0)
		{

			foreach ($result['constants'] as $method)
			{
		?>
				<?php p($method); ?> 
		<?php
			}
		}
		?>
	</div>


	<div class="tab-pane <?php if (count($result['constants']) == 0)	{	?>	active <?php } ?>" id="attributes">

		<!-- Static properties -->

		<?php

				$content = app()->getDocumentationHelper()->generateHtmlProperties('static', $result);
				echo $content;	
		?>

		<!-- Protected properties -->

		<?php

				$content = app()->getDocumentationHelper()->generateHtmlProperties('protected', $result);
				echo $content;	
		?>

		<!-- Private properties -->

		<?php

				$content = app()->getDocumentationHelper()->generateHtmlProperties('private', $result);
				echo $content;	
		?>

		<!-- Public properties -->

		<?php

				$content = app()->getDocumentationHelper()->generateHtmlProperties('public', $result);
				echo $content;	
		?>	
	</div>


	<div class="tab-pane <?php if (count($result['constants']) == 0 && $result['hasProperties'] == 0)	{	?>	active <?php } ?>" id="properties">
		<!-- Model properties-->

		<?php

		if (count($result['objectProperties']) > 0)
		{
		?>
			<div>
				<table class="table table-hover table-bordered">
					<thead>
						<tr>
							<th>Property Name</th>
							<th>Description</th>
							<th>Type</th>
						</tr>
					</thead>
					<tbody>
		<?php
			foreach ($result['objectProperties'] as $propertyName => $propertyDetails)
			{

		?>
						<tr>
							<td><?php p($propertyName); ?></td>
							<td>
							<?php
								foreach ($propertyDetails as $name => $details)
								{
									if ($name == 'loopTypeProperty')
									{
										$type = $details;

										continue;
									}

									// Is it type object ?

									if
									(
										$name !== 'object' &&
										empty($details) === false
									)
									{
										if (is_array($details))
										{
											$details = json_encode($details);
										}
							?>

										<li><?php p($name); ?> : <?php p($details); ?> </li>
							<?php					
									}
								}
							?>
							</td>
							<td>
								<?php p($type); ?>
							</td>
						</tr>
		<?php
			}
		?>
					</tbody>
				</table>
			</div>

		<?php
		}
		?>
	</div>

	<div class="tab-pane" id="io">
		
		<!-- Model properties-->

		<?php

		if (count($result['ioProperties']) > 0 && $directory == 'Model')
		{
				$content = app()->getDocumentationHelper()->generateHtmlIO($result);
				echo $content;	
		}
		?>
	</div>

	<div class="tab-pane <?php if (count($result['constants']) == 0 && $result['hasProperties'] == 0 && count($result['objectProperties']) == 0){	?>active<?php } ?>" id="methods">
		<!-- Static methods -->

		<?php

				$content = app()->getDocumentationHelper()->generateHtmlMethod('static', $result);
				echo $content;	
		?>

		<!-- Protected methods -->

		<?php

				$content = app()->getDocumentationHelper()->generateHtmlMethod('protected', $result);
				echo $content;	
		?>

		<!-- Private methods -->

		<?php

				$content = app()->getDocumentationHelper()->generateHtmlMethod('private', $result);
				echo $content;	
		?>

		<!-- Public methods -->

		<?php

				$content = app()->getDocumentationHelper()->generateHtmlMethod('public', $result);
				echo $content;	
		?>	
	</div>


	<div class="tab-pane <?php if (count($result['constants']) == 0 && $result['hasProperties'] == 0 && count($result['objectProperties']) == 0 && $result['hasMethods'] == 0){	?>active<?php } ?>" id="APIs">

		<!-- Static Apis -->
		<?php

				$content = app()->getDocumentationHelper()->generateHtmlAPI($result);
				echo $content;	
		?>
	</div>

	<div class="tab-pane <?php if (count($result['constants']) == 0 && $result['hasProperties'] == 0 && count($result['objectProperties']) == 0 && $result['hasMethods'] == 0 && isset($result['API']) === false){	?>active<?php } ?>" id="dependencies">
		<!-- Dependencies-->

		<?php

		if 
		(
			isset($result['dependencies']) === true && 
			count($result['dependencies']) >0
		)
		{
				foreach ($result['dependencies'] as  $extensionDependency => $directoriesDependency)
				{
		?>
					<h4 style="text-align: center;">
						<a href="<?php p(url('[Loop]/page/admin/documentation/extension/') . '?extensionId=' . $extensionDependency);?>">
							<?php p($extensionDependency); ?> 
						</a>
					</h4>	
					<div>
						<table class="table table-hover table-bordered">
							<thead>
								<tr>
									<th>Concept</th>
									<th>Name</th>
								</tr>
							</thead>
							<tbody>
							<?php
										foreach ($directoriesDependency as $directoryDependency => $filesDependency)
										{

											foreach ($filesDependency as $fileDependency)
											{
							?>
												<tr>
													<td>
														<?php p($directoryDependency); ?>
													</td>
													<td>									
														<?php
																// Link if it's a model or a class

																if 
																(
																	$directoryDependency == 'Class' ||
																	$directoryDependency == 'Model' 
																)
																{
														?>
															<a href="<?php p(url('[Loop]/page/admin/documentation/concept/') . '?extensionId=' . $extensionDependency .'&directory=' . $directoryDependency . '&file=' . $fileDependency);?>">

														<?php 
																}
																
																p($fileDependency); 
																
																if 
																(
																	$directoryDependency == 'Class' ||
																	$directoryDependency == 'Model' 
																)
																{
														?>
															</a>
															<?php
																}
															?>
													</td>
												<?php
											}
										}

									}
							?>
							</tbody>
						</table>
					</div>
		<?php
		}
		?>
	</div>

</div>